##Data Cleaning and Mergng  

rm(list=ls())

library(foreign)
library(readstata13)
library(car)
library(psycho)
library(lme4)
library(stargazer)
library(texreg)

setwd("...")

## LAPOP data 

fulldata<-read.dta13("2016_merge (07172017).dta")

modeldata<-fulldata[,c(1,3, 14, 20, 523, 478, 1205, 1071, 1073, 1437, 379, 1224, 979, 1074, 1076, 454, 581, 1060, 1105)]


names<-c("country", "year", "urban", "female", "ClimProb", "Edu", "PartyID", "PersonalIncome", "HHIncome", "ideo", "pol_know_rate", "id_w_party", "pol_interest", "married", "n_child", "risk_climate", "media", "age", "redist")

names(modeldata)<-names 

modeldata$ClimProb<-recode(modeldata$ClimProb, "'Very Serious' = 4; 'Somewhat Serious' = 3; 'A Little Serious' = 2; 'Not Serious at All' = 1; else = NA")

modeldata$female<-recode(modeldata$female, "'Female' = 1; 'Male' = 0; else = NA")

modeldata$Republican<-recode(modeldata$PartyID, "'Republican' = 1; else=0")

modeldata$pol_know_rate<-recode(modeldata$pol_know_rate, " 'Very Low' = 1; 'Low' = 2; 'Neither High Nor Low' = 3; 'High' = 4; 'Very High'=5; else=NA ")

modeldata$id_w_party<-recode(modeldata$id_w_party, " 'Yes' = 1; else = '0'")

modeldata$married<-gsub("\\s*\\([^\\)]+\\)","",as.character(modeldata$married))


modeldata$married<-recode(modeldata$married, " 'Married' = 1; 'Common law marriage' = 1; 'Civil Union' = 1; else=0")

modeldata$risk_climate<-recode(modeldata$risk_climate, " 'Not Likely at All' = 1; 'Unlikely' =2; 'Somewhat Likely'=3; 'Very Likely'=4; else=NA ")

modeldata$media<-recode(modeldata$media, " 'Never' = 1; 'Rarely' = 2; 'A few times a month' = 3; 'A few times a week' =4; 'Daily' =5; else = NA  ")

modeldata$pol_interest <-recode(modeldata$pol_interest, " 'None' = 1; 'Little' = 2; 'Some' = 3; 'A lot' =4; else = NA  ")

modeldata$urban <-recode(modeldata$urban, " 'Urban' = 1; 'Rural' = 0; else= NA")


modeldata$female<-as.numeric(as.character(modeldata$female))
modeldata$ClimProb <-as.numeric(as.character(modeldata$ClimProb))
modeldata$Edu <-as.numeric(as.character(modeldata$Edu))
modeldata$pol_know_rate <-as.numeric(as.character(modeldata$pol_know_rate))
modeldata$id_w_party <-as.numeric(as.character(modeldata$id_w_party))
modeldata$pol_interest <-as.numeric(as.character(modeldata$pol_interest))
modeldata$risk_climate <-as.numeric(as.character(modeldata$risk_climate))
modeldata$media <-as.numeric(as.character(modeldata$media))
modeldata$urban <-as.numeric(as.character(modeldata$urban))


modeldata$ClimStand<-standardize(modeldata$ClimProb)

#men & women

men<-subset(modeldata, female==0)
women<-subset(modeldata, female==1)

tapply(men$ClimProb, men$country, mean, , na.rm=TRUE) 
tapply(women$ClimProb, women$country, mean, , na.rm=TRUE) 

#add GDPPC to individual data

modeldata$GDPPC<-recode(modeldata$country, "'Mexico' = 8910.33; 'Guatemala' = 4470.99;'El Salvador' = 3889.31;'Honduras' = 2480.13;'Nicaragua' = 2221.81;'Costa Rica' = 11677.27;'Panama' = 15196.40;'Colombia' = 6408.92;'Ecuador' = 6273.49;'Bolivia' = 3393.96;'Peru' = 6571.93;'Paraguay' = 5823.77;'Chile' = 15346.45;'Uruguay' = 16245.60;'Brazil' = 9821.41;'Venezuela' = 15692.41;'Argentina' = 14398.36;'Dominican Republic' = 7052.26;'Haiti' = 765.68;'Jamaica' = 5114.04;'Guyana' = 4655.14;'Grenada' = 10451.03;'St. Lucia' = 9715.19;'Dominica' = 6719.34;'Antigua & Barbuda' = 14803.01;'St. Vincent & the Grenadines' = 7145.08;'St. Kitts & Nevis' = 17924.07;'United States' = 59531.66;'Canada' = 45032.12")

modeldata$GDPPC<-as.numeric(as.character(modeldata$GDPPC))

##modeldata is indiidual level data set  ("LAPOPData2.csv" data)
##Country level data: gaps and levels (used to create figures 1 & 2 in the data)

menlevel<-tapply(men$ClimProb, men$country, mean, , na.rm=TRUE) 
womenlevel<-tapply(women$ClimProb, women$country, mean, , na.rm=TRUE) 
diffs<-womenlevel-menlevel

CountryLevelAB<-as.data.frame(cbind(womenlevel, menlevel, diffs)) ##creates the "AmericasLevels.csv" dataset and the "LADiffsStand.csv"

##Pew data cleaning 

rm(list=ls())


library(foreign)
library(readstata13)
library(car)
library(psycho)
library(lme4)
library(stargazer)
library(texreg)
#install.packages("robustHD")
library(robustHD)
library(effectsize)


Pew<-as.data.frame(read.spss("Pew Research Global Attitudes Spring 2015 Dataset for Web FINAL.sav")) #40 countries 45,435 obs


modeldata<-Pew[,c(2,465, 662, 36, 104, 105, 112:116, 141, 516:597, 513)]

#recode income 

modeldata$Q165ARG<-as.numeric(modeldata$Q165ARG)
modeldata$Q165ARG<-recode(modeldata$Q165ARG, "23:25 = NA")
modeldata$Q165ARG<-23-modeldata$Q165ARG
modeldata$Q165ARG<-standardize(modeldata$Q165ARG)

table(modeldata$Q165AUS)
modeldata$Q165AUS <-as.numeric(modeldata$Q165AUS)
modeldata$Q165AUS <-recode(modeldata$Q165AUS, "22:23 = NA")
modeldata$Q165AUS <-standardize(modeldata$Q165AUS)

table(modeldata$Q165BRA)
modeldata$Q165BRA <-as.numeric(modeldata$Q165BRA)
modeldata$Q165BRA <-standardize(modeldata$Q165BRA)

table(modeldata$Q165BRA)
modeldata$Q165BRA <-as.numeric(modeldata$Q165BRA)
modeldata$Q165BRA <-standardize(modeldata$Q165BRA)

table(modeldata$Q165BRI)
modeldata$Q165BRI <-as.numeric(modeldata$Q165BRI)
modeldata$Q165BRI <-recode(modeldata$Q165BRI, "11:12 = NA")
modeldata$Q165BRI <-standardize(modeldata$Q165BRI)

table(modeldata$Q165BUR)
modeldata$Q165BUR <-as.numeric(modeldata$Q165BUR)
modeldata$Q165BUR <-recode(modeldata$Q165BUR, "11:12 = NA")
modeldata$Q165BUR <-standardize(modeldata$Q165BUR)

table(modeldata$Q165CAN)
modeldata$Q165CAN <-as.numeric(modeldata$Q165CAN)
modeldata$Q165CAN <-recode(modeldata$Q165CAN, "11:12 = NA")
modeldata$Q165CAN <-standardize(modeldata$Q165CAN)

table(modeldata$Q165CHL)
modeldata$Q165CHL <-as.numeric(modeldata$Q165CHL)
modeldata$Q165CHL <-recode(modeldata$Q165CHL, "14:15 = NA")
modeldata$Q165CHL <-standardize(modeldata$Q165CHL)

table(modeldata$Q165CHI)
modeldata$Q165CHI <-as.numeric(modeldata$Q165CHI)
modeldata$Q165CHI <-recode(modeldata$Q165CHI, "22:25 = NA")
modeldata$Q165CHI <-standardize(modeldata$Q165CHI)

table(modeldata$Q165ETH)
modeldata$Q165ETH <-as.numeric(modeldata$Q165ETH)
modeldata$Q165ETH <-recode(modeldata$Q165ETH, "14:15 = NA")
modeldata$Q165ETH <-standardize(modeldata$Q165ETH)

table(modeldata$Q165FRA)
modeldata$Q165FRA <-as.numeric(modeldata$Q165FRA)
modeldata$Q165FRA <-recode(modeldata$Q165FRA, "11:12 = NA")
modeldata$Q165FRA <-standardize(modeldata$Q165FRA)

table(modeldata$Q165GER)
modeldata$Q165GER <-as.numeric(modeldata$Q165GER)
modeldata$Q165GER <-recode(modeldata$Q165GER, "10:11 = NA")
modeldata$Q165GER <-standardize(modeldata$Q165GER)

table(modeldata$Q165GHA)
modeldata$Q165GHA <-as.numeric(modeldata$Q165GHA)
modeldata$Q165GHA <-recode(modeldata$Q165GHA, "12:13 = NA")
modeldata$Q165GHA <-standardize(modeldata$Q165GHA)

table(modeldata$Q165INDIA)
modeldata$Q165INDIA <-as.numeric(modeldata$Q165INDIA)
modeldata$Q165INDIA <-recode(modeldata$Q165INDIA, "20:21 = NA")
modeldata$Q165INDIA <-standardize(modeldata$Q165INDIA)

modeldata[modeldata=="Don’t know"]<-NA
modeldata[modeldata=="Refused"]<-NA
modeldata[modeldata=="No income"]<-NA

table(modeldata$Q165INDO)
modeldata$Q165INDO <-as.numeric(modeldata$Q165INDO)
modeldata$Q165INDO <-standardize(modeldata$Q165INDO)

table(modeldata$Q165ISR)
modeldata$Q165ISR <-as.numeric(modeldata$Q165ISR)
modeldata$Q165ISR <-standardize(modeldata$Q165ISR)

table(modeldata$Q165ITA)
modeldata$Q165ITA <-as.numeric(modeldata$Q165ITA)
modeldata$Q165ITA <-standardize(modeldata$Q165ITA)

table(modeldata$Q165JPN)
modeldata$Q165JPN <-as.numeric(modeldata$Q165JPN)
modeldata$Q165JPN <-recode(modeldata$Q165JPN, "16 = NA")
modeldata$Q165JPN <-standardize(modeldata$Q165JPN)

table(modeldata$Q165JOR)
modeldata$Q165JOR <-as.numeric(modeldata$Q165JOR)
modeldata$Q165JOR <-standardize(modeldata$Q165JOR)

table(modeldata$Q165KEN)
modeldata$Q165KEN <-as.numeric(modeldata$Q165KEN)
modeldata$Q165KEN <-standardize(modeldata$Q165KEN)

table(modeldata$Q165LEB)
modeldata$Q165LEB <-as.numeric(modeldata$Q165LEB)
modeldata$Q165LEB <-standardize(modeldata$Q165LEB)

table(modeldata$Q165MAL)
modeldata$Q165MAL <-as.numeric(modeldata$Q165MAL)
modeldata$Q165MAL <-standardize(modeldata$Q165MAL)

table(modeldata$Q165MEX)
modeldata$Q165MEX <-as.numeric(modeldata$Q165MEX)
modeldata$Q165MEX <-standardize(modeldata$Q165MEX)

table(modeldata$Q165NIG)
modeldata$Q165NIG <-as.numeric(modeldata$Q165NIG)
modeldata$Q165NIG <-recode(modeldata$Q165NIG, "12 = NA")
modeldata$Q165NIG <-standardize(modeldata$Q165NIG)

table(modeldata$Q165PAK)
modeldata$Q165PAK <-as.numeric(modeldata$Q165PAK)
modeldata$Q165PAK <-recode(modeldata$Q165PAK, "9 = NA")
modeldata$Q165PAK <-standardize(modeldata$Q165PAK)

table(modeldata$Q165PAL)
modeldata$Q165PAL <-as.numeric(modeldata$Q165PAL)
modeldata$Q165PAL <-recode(modeldata$Q165PAL, "13 = NA")
modeldata$Q165PAL <-standardize(modeldata$Q165PAL)

table(modeldata$Q165PER)
modeldata$Q165PER <-as.numeric(modeldata$Q165PER)
modeldata$Q165PER <-standardize(modeldata$Q165PER)

table(modeldata$Q165PHI)
modeldata$Q165PHI <-as.numeric(modeldata$Q165PHI)
modeldata$Q165PHI <-standardize(modeldata$Q165PHI)

table(modeldata$Q165POL)
modeldata$Q165POL <-as.numeric(modeldata$Q165POL)
modeldata$Q165POL <-standardize(modeldata$Q165POL)

table(modeldata$Q165RSA)
modeldata$Q165RSA <-as.numeric(modeldata$Q165RSA)
modeldata$Q165RSA <-recode(modeldata$Q165RSA, "31 = NA")
modeldata$Q165RSA <-standardize(modeldata$Q165RSA)

table(modeldata$Q165RUS)
modeldata$Q165RUS <-as.numeric(modeldata$Q165RUS)
modeldata$Q165RUS <-standardize(modeldata$Q165RUS)

table(modeldata$Q165SEN)
modeldata$Q165SEN <-as.numeric(modeldata$Q165SEN)
modeldata$Q165SEN <-standardize(modeldata$Q165SEN)

table(modeldata$Q165SKOR)
modeldata$Q165SKOR <-as.numeric(modeldata$Q165SKOR)
modeldata$Q165SKOR <-recode(modeldata$Q165SKOR, "15 = NA")
modeldata$Q165SKOR <-standardize(modeldata$Q165SKOR)

table(modeldata$Q165SPA)
modeldata$Q165SPA <-as.numeric(modeldata$Q165SPA)
modeldata$Q165SPA <-recode(modeldata$Q165SPA, "12 = NA")
modeldata$Q165SPA <-standardize(modeldata$Q165SPA)

table(modeldata$Q165TAN)
modeldata$Q165TAN <-as.numeric(modeldata$Q165TAN)
modeldata$Q165TAN <-recode(modeldata$Q165TAN, "15 = NA")
modeldata$Q165TAN <-standardize(modeldata$Q165TAN)

table(modeldata$Q165TUR)
modeldata$Q165TUR <-as.numeric(modeldata$Q165TUR)
modeldata$Q165TUR <-recode(modeldata$Q165TUR, "16 = NA")
modeldata$Q165TUR <-standardize(modeldata$Q165TUR)

table(modeldata$Q165UGA)
modeldata$Q165UGA <-as.numeric(modeldata$Q165UGA)
modeldata$Q165UGA <-recode(modeldata$Q165UGA, "15 = NA")
modeldata$Q165UGA <-standardize(modeldata$Q165UGA)

table(modeldata$Q165UKR)
modeldata$Q165UKR <-as.numeric(modeldata$Q165UKR)
modeldata$Q165UKR <-standardize(modeldata$Q165UKR)

table(modeldata$Q165US)
modeldata$Q165US <-as.numeric(modeldata$Q165US)
modeldata$Q165US <-recode(modeldata$Q165US, "10 = NA")
modeldata$Q165US <-standardize(modeldata$Q165US)

table(modeldata$Q165VEN)
modeldata$Q165VEN <-as.numeric(modeldata$Q165VEN)
modeldata$Q165VEN <-recode(modeldata$Q165VEN, "22 = NA")
modeldata$Q165VEN <-standardize(modeldata$Q165VEN)

table(modeldata$Q165VIE)
modeldata$Q165VIE <-as.numeric(modeldata$Q165VIE)
modeldata$Q165VIE <-recode(modeldata$Q165VIE, "25 = NA")
modeldata$Q165VIE <-standardize(modeldata$Q165VIE)

Income<-modeldata[,c(13:94)]

Income[is.na(Income)]<-0


Income $StandIncome<-Income $Q165ARG + Income $Q165AUS + Income $Q165BRA + Income $Q165BRI + Income $Q165BUR      + Income $Q165CAN      + Income $Q165CHL     + Income $Q165CHI    + Income $Q165ETH      + Income $Q165FRA    + Income $Q165GER    + Income $Q165GHA       + Income $Q165INDIA   + Income $Q165INDO   + Income $Q165ISR      + Income $Q165ITA    + Income $Q165JPN     + Income $Q165JOR+       + Income $Q165KEN     + Income $Q165LEB    + Income $Q165MAL     + Income $Q165MEX    + Income $Q165NIG     + Income $Q165PAK     + Income $Q165PAL     + Income $Q165PER     + Income $Q165PHI     + Income $Q165POL    + Income $Q165RSA     + Income $Q165RUS     + Income $Q165SEN      + Income $Q165SKOR     + Income $Q165SPA     + Income $Q165TAN     + Income $Q165TUR    + Income $Q165UGA     + Income $Q165UKR      + Income $Q165US      + Income $Q165VEN     + Income $Q165VIE  

modeldata<-cbind(modeldata, Income$StandIncome)

modeldata<-modeldata[,c(1:12,95,96)]

names<-c("Country", "Female", "Ideo", "ClimConcen", "ClimSerious", "Tech", "SupportParis", "WhenHarm", "PesonalHarm", "WorryType", "RichPay", "WomensRights", "Edu", "StandIncome")

names(modeldata)<-names

modeldata$Female<-recode(modeldata$Female, "'Female'=1; 'Male'=0; else=NA")
modeldata$Female<-as.numeric(as.character(modeldata$Female))

modeldata$Ideo<-recode(modeldata$Ideo, "' (Left)' = 1; 1=2; 2=3; 3=4; 4=5; 5=6; '(Right) ' = 7; else=NA")
modeldata$Ideo <-as.numeric(as.character(modeldata$Ideo))

#from not at all concerned to very concerned 
modeldata$ClimConcen<-recode(modeldata$ClimConcen, "'Not at all concerned' = 1; 'Not too concerned'=2; 'Somewhat concerned'=3; 'Very concerned'=4; else=NA")
modeldata$ClimConcen <-as.numeric(as.character(modeldata$ClimConcen))

#from not a a problem to very serious
modeldata$ClimSerious<-recode(modeldata$ClimSerious, "'Not a problem' = 1; 'Not too serious'=2; 'Somewhat serious'=3; 'Very serious'=4; else=NA")
modeldata$ClimSerious <-as.numeric(as.character(modeldata$ClimSerious))

#1 = Technology can solve the problem without major changes; 0 =Have to make major changes; 
modeldata$Tech <-recode(modeldata$Tech, "'Technology can solve the problem without major changes' = 1; 'Have to make major changes'=0; else=NA")
modeldata$Tech <-as.numeric(as.character(modeldata$Tech))

#1 = support; 0 = oppose
modeldata$SupportParis <-recode(modeldata$SupportParis, "'Support' = 1; 'Oppose'=0; else=NA")
modeldata$SupportParis <-as.numeric(as.character(modeldata$SupportParis))

#from now to never; higher values more in the future 
modeldata$WhenHarm <-recode(modeldata$WhenHarm, "'Now' = 1; 'In the next few years'=2; 'Not for many years'=3; c('Never', 'Climate change does not exist (Volunteered)')=4; else=NA")
modeldata$WhenHarm <-as.numeric(as.character(modeldata$WhenHarm))

#from now to never; higher values more in the future 
modeldata$PesonalHarm <-recode(modeldata$PesonalHarm, "c('Not at all concerned', 'Climate change does not exist (Volunteered)') = 1; 'Not too concerned'=2; 'Somewhat concerned'=3; 'Very concerned'=4; else=NA")
modeldata$PesonalHarm <-as.numeric(as.character(modeldata$PesonalHarm))

#"RichPay"
modeldata$RichPay <- gsub("'", '', modeldata$RichPay)
modeldata$RichPay <-recode(modeldata$RichPay, "'Rich countries, such as the U.S., Japan and Germany, should do more than developing countries because they have produced' = 1; 'Developing countries should do just as much as rich countries because they will produce most of the worlds greenhouse g'=0; else=NA")
modeldata$RichPay <-as.numeric(as.character(modeldata$RichPay))

# "WomensRights"
modeldata$WomensRights <-recode(modeldata$WomensRights, "'Not important at all' = 1; 'Not too important'=2; 'Somewhat important'=3; 'Very important'=4; else=NA")
modeldata$WomensRights <-as.numeric(as.character(modeldata$WomensRights))

modeldata$Edu <- gsub("'", '', modeldata$Edu)

modeldata$Edu<-recode(modeldata$Edu, " 'Dont know' = NA")

#Attach GDP 

Country<-c('Argentina', 'Australia', 'Brazil', 'Burkina Faso', 'Chile', 'China', 'Canada', 'Ethiopia', 'France', 'Germany', 'Ghana', 'India', 'Indonesia', 'Israel', 'Italy', 'Japan', 'Jordan', 'Kenya', 'Lebanon', 'Malaysia', 'Mexico', 'Nigeria', 'Pakistan', 'Palestinian territories', 'Peru', 'Philippines', 'Poland', 'Russia', 'Senegal', 'South Africa', 'South Korea', 'Spain', 'Tanzania', 'Turkey', 'Uganda', 'Ukraine', 'United Kingdom', 'United States', 'Venezuela', 'Vietnam')

GDP<-c(14398.4, 53799.9, 9821.4, 642.0, 15346.4, 8827.0, 45032.1, 767.6, 38476.7, 44469.9, 2046.1, 1942.1, 3846.9, 40270.3, 31953.0, 38428.1, 4129.8, 1594.8, 8808.6, 9951.5, 8910.3, 1968.4, 1547.9, 3094, 6571.9, 2989.0, 13863.2, 10743.1, 1329.3, 6151.1, 29742.8, 28156.8, 936.3, 10546.2, 606.5, 2639.8, 39720.4, 59531.7, 15692, 2342.2)

Country<-as.data.frame(cbind(Country, GDP))
Country$GDP<-as.numeric(as.character(Country$GDP))
names<-c("Country", "GDPPC")
names(Country)<-names
summary(Country)

#standardize ClimSerious scores

modeldata$ClimStand<-standardize(modeldata$ClimSerious)

temp<-subset(modeldata, is.na(modeldata$ClimStand)==F)

PewData<-merge(modeldata, CountryLevel, by="Country") #correspondends to "PewData.csv" data file for main models (Table 1)

Women<-subset(temp, Female==1)
Men<-subset(temp, Female==0)

FemMean<-tapply(Women$ClimStand, Women$Country, mean)
MenMean<-tapply(Men$ClimStand, Men$Country, mean)

Diffs<-FemMean-MenMean

CountryLevel<-cbind(Country, Diffs) #creates the "PewLevels.csv" dataset and the "CountryLevelPew.csv" dataset, used to create Figures 1 & 2 (Pew data)

#Netquest data
#Note data to clean and process STM model results are in the main "FinalReplicationCode" R script 

modeldata<-read.csv("fulldata.csv")

modeldata<-subset(modeldata, modeldata$country != "Argentina_1") #note this was from an error in data collection where they sampled respondents in Argentina twice 

modeldata$age<-recode(modeldata$age, " '18-24' = 21; '25 - 34' = 30; '35 - 44' = 40; '45 - 54' = 50; '55 - 64' = 60;  '65 - 74' = 70; '75 - 84' = 80; '85 or older' = 85; 28121996 = NA")
modeldata$age<-as.numeric(as.character(modeldata$age))

modeldata$edu<-gsub("[[:punct:]]", " ", modeldata$edu)

modeldata$edu<-str_replace_all(modeldata$edu, "[[:punct:]]", " ")

modeldata$secondary<-recode(modeldata$edu, " '16 years, 4 years of college (Bachelor's degree)' = 1; '17 years, 5 years or more of university/graduate school' = 1; 'Antiguo Bachiller elemental \x89\xdb\xd2 EGB (Graduado escolar)-EPO' =1; 'Antiguo Bachiller Superior \x89\xdb\xd2 BUP \x89\xdb\xd2ESO' = 1; 'Diplomado o Maestr\xcc_a' = 1; 'Doctorado' = 1; 'Doutorado' = 1; 'Doutoramento' = 1; 'Ensino superior politÌ©cnico: bacharelato de 3 anos (magistÌ©rio primÌÁrio, serviÌ¤o social, regente agrÌ_cola); Antigos cursos mÌ©dios' =1; '' " )

modeldata$standard_env<-standardize(modeldata$env)

women<-subset(modeldata, female == 1)
men<-subset(modeldata, female == 0)

#in our data, gap correlated with GDP 

temp1<-women[, c(11, 15, 16, 17)]
temp1<-na.omit(temp1)

temp2<-men[, c(11, 15, 16, 17)]
temp2<-na.omit(temp2)

women_country<-tapply(temp1 $standard_env, temp1 $country, mean)
men_country<-tapply(temp2 $standard_env, temp2 $country, mean)
gaps_country<-women_country-men_country

GDP<-tapply(temp1$GDPPC, temp1 $country, mean)

country<-as.data.frame(cbind(gaps_country, GDP))

cor.test(country$gaps_country, log(country$GDP)) 

#country-level dataset with correlations 

country<-c("Argentina", "Brazil", "Chile", "Colombia", "Mexico", "USA", "Peru", "Portugal", "Spain", "UK")
gaps<-c(0.12688307, 0.15528836, 0.06648368, 0.01371142, 0.06469660, 0.27705806, 0.033796, 0.073931, 0.128052, 0.240744)
#gaps<-as.numeric(as.character(country$gaps_country[2:7]))
GDP<-c(14401, 9812, 15346, 6301, 8902, 59531, 6941, 23407, 30370, 42943)
linkedfate_corrM<-c(0.02110654, 0.0806762, 0.01873029, 0.01814427, 0.01024284, -0.1832581, 0.1102889, 0.08237322, 0.03968898, 0.01737517) #maybe double check coding for last countries 
wr_corrM<-c(0.0511396, 0.1552063, 0.08475153, 0.04541395, 0.0452468, 0.4147932, -0.0110367, 0.06900761, 0.338934, 0.3084992)
wol_corrM<-c(0.3089968, 0.5091514, 0.3156873, 0.1835743, 0.1708609, 0.7471679, 0.2392919, 0.2821992, 0.5253034, 0.5507002)
wol_corrW<-c( 0.3169349, 0.2229473, 0.1377174, 0.1942932, 0.2772736, 0.6829573, 0.2414203, 0.2098708, 0.3947405, 0.4420552)
gaps_stan_wi<-c(0.2363374, 0.2223882, 0.1537475, 0.03508235, 0.1690042, 0.2604584, 0.0793095, 0.1582088, 0.2589387, 0.2902715)
wr_corrW<-c(0.01496203, 0.09978618, 0.09042712, -0.04216087, 0.08275417, 0.4218606, 0.08250477, 0.06303355, 0.1546673, 0.1685332)
gaps_stan_across<-c(0.1981409, 0.2424987, 0.1038211, 0.0214118, 0.1010304, 0.4326546, 0.0527756, 0.1154518, 0.1999654, 0.3759471)
## add levels 

MenLevels<-c(-0.02640748, -0.13996300,  0.18714485,  0.26434870,  0.24245594, -1.16884774,  0.18074654,  0.07654843,  0.00240258, -0.81939601)
WomenLevels<-c(0.1717335, 0.1025357, 0.2909660, 0.2857605, 0.3434863, -0.7361931, 0.2335221,   0.1920003,   0.2023679,  -0.4434489)

all_country<-as.data.frame(cbind(country, gaps, GDP, linkedfate_corrM, wr_corrM, wr_corrW, wol_corrM, wol_corrW, gaps_stan_wi, gaps_stan_across, MenLevels, WomenLevels))

names(all_country)<-c("country", "gaps", "GDPPC", "linkedfate_corrM", "wr_corrM", "wr_corrW", "wol_corrM", "wol_corrW", "gaps_stan_wi", "gaps_stan_across", "men_levels", "women_levels")

all_country$gaps<-as.numeric(as.character(all_country$gaps))
all_country$GDPPC <-as.numeric(as.character(all_country$GDPPC))
all_country$linkedfate_corrM <-as.numeric(as.character(all_country$linkedfate_corrM))
all_country$wr_corrM <-as.numeric(as.character(all_country$wr_corrM))
all_country$wr_corrW <-as.numeric(as.character(all_country$wr_corrW))
all_country$wol_corrM <-as.numeric(as.character(all_country$wol_corrM))
all_country$wol_corrW <-as.numeric(as.character(all_country$wol_corrW))
all_country$gaps_stan_wi <-as.numeric(as.character(all_country$gaps_stan_wi))
all_country$gaps_stan_across <-as.numeric(as.character(all_country$gaps_stan_across))

#all_country is dataset in files "NetquestCountry.csv" (used to produce Figure 4) and "NetquestWomensRights.csv" (used to produce Figure 7)
